< previous page page_570 next page >

Page 570
9f31265bb40b592b1929e18a47ab28e5.gif
   With oSysInfo
      ' Get memory information.
      lblTotPhys = FormatK(.TotalPhysical)
      lblAvailPhys = FormatK(.AvailPhysical)
      lblTotVirtual = FormatK(.TotalVirtual)
      lblAvailVirtual = FormatK(.AvailVirtual)

      ' Get processor information.
      lblNumberOrfProcessors = .NumCPU
      lblCPUType = .CPUType

      ' Get path information.
      lblWindowsDir = .WinDir
      lblSystemDir = .WinSysDir
      lblTempDir = .WinTempDir

      ' Get OS Information
      lblOS = .OperatingSystem
   End With
End Sub
As you can see, this code looks very simple. This is because all of the functionality is hidden in a class module called clsSystemInfo. This class module retrieves the system information in each call to each property. Also, note the function called FormatK(). This function formats the total amount of memory into a value expressed in kilobytes (1,024 bytes):
9f31265bb40b592b1929e18a47ab28e5.gif
Private Function FormatK(ByVal lngValue As Long) As String
   FormatK = Format(Fix(lngValue / 1024), _
                  "###,###") & "K"
End Function
Now, lets take a look at the System Information class.
The System Information Class
Instead of coding all these Windows API calls in the front-end application, you can encapsulate these calls in a class. The clsSystemInfo class has many declarations of Windows API calls, user-defined types, and constants that are used to fill in all the properties of the class. Heres the code:

 
< previous page page_570 next page >

If you like this book, buy it!